package cn.topkinson.rocketmq.seckill.listener;

import cn.topkinson.rocketmq.seckill.common.RocketConstant;
import cn.topkinson.rocketmq.seckill.entity.dto.OrderMsg;
import cn.topkinson.rocketmq.seckill.service.SeckillService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @Author huangzihao
 * @Date 2021/1/18 14:31
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = RocketConstant.TOPIC_ORDER,
        consumerGroup= RocketConstant.GROUP_ORDER,
        consumeThreadMax = 1,
        consumeMode = ConsumeMode.ORDERLY)
public class OrderListener implements RocketMQListener<String> {

    @Override
    public void onMessage(String msg) {
        OrderMsg orderMsg = JSON.parseObject(msg, OrderMsg.class);
        log.info("消费开始，创建订单：{}",orderMsg);
    }
}
